import { ref } from 'vue'
import { followOrUnfollow } from '@/api/consult'
import type { FollowType } from '@/types/consult'
//  封装逻辑，规范 usexxx,表示使用某些功能
export const useFollow = (type: FollowType = 'doc') => {
    const loading = ref(false)
    // {a,b} 类型，传值的时候，{a,b,c}也可以，这是类型兼容： 多的可以给少的
    const follow = async (item: { id: string; likeFlag: 0 | 1 }) => {
        loading.value = true
        try {
            await followOrUnfollow(item.id, type)
            item.likeFlag = item.likeFlag === 1 ? 0 : 1
        } catch (error) {
            loading.value = false
        }
    }
    return { loading, follow }
}